package com.fishery.monitor.controller;

import com.fishery.entity.Result;
import com.fishery.entity.StatusCode;
import com.fishery.monitor.pojo.MonitorBase;
import com.fishery.monitor.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: whz
 * @Description:
 * @Date Created in 2021/3/19
 */
@Api(tags = {"基地视频接口"})
@RestController
@CrossOrigin
@RequestMapping({"/monitor"})
public class MonitorVideoController {
    @Autowired
    private BaseService baseService;

    public MonitorVideoController() {
    }

    @ApiOperation("用户查看该基地监控，只显示status为1")
    @RequestMapping(
            value = {"/trace"},
            method = {RequestMethod.GET}
    )
    public Result traceMonitor(@RequestParam("baseId") String baseId) {
        List<MonitorBase> monitorVideoList = this.baseService.traceMonitor(baseId);
        return monitorVideoList.size() == 0 ? new Result(false, StatusCode.ACCESSERROR, "基地未开放监控", (Object)null) : new Result(true, StatusCode.OK, "调用成功", monitorVideoList);
    }

    @ApiOperation("增加")
    @RequestMapping(
            value = {"/add"},
            method = {RequestMethod.POST}
    )
    public Result add(@RequestBody @ApiParam(name = "基地视频对象",required = true,value = "monitorVideo") MonitorBase monitorBase) {
        this.baseService.addVideo(monitorBase);
        return Result.success("增加成功");
    }

    @ApiOperation("修改状态")
    @RequestMapping(
            value = {"/modify/{id}/{status}"},
            method = {RequestMethod.GET}
    )
    public Result modify(@PathVariable String id, @PathVariable String status) {
        this.baseService.modifyStatus(id, status);
        return Result.success("修改成功");
    }

    @ApiOperation("更新")
    @RequestMapping(
            value = {"/update"},
            method = {RequestMethod.POST}
    )
    public Result upData(@RequestBody @ApiParam(name = "基地视频对象",required = true,value = "monitorVideo") MonitorBase monitorBase) {
        this.baseService.upData(monitorBase);
        MonitorBase vs = (MonitorBase)this.baseService.getById(monitorBase.getId());
        return new Result(true, StatusCode.OK, "更新成功", vs);
    }

    @ApiOperation("刷新基地监控")
    @RequestMapping(
            value = {"/refresh"},
            method = {RequestMethod.POST}
    )
    public Result refresh(@RequestParam("id") String id) {
        this.baseService.refresh(id);
        return Result.success("刷新成功");
    }
}
